﻿using Adnc.Application.Shared;
using Adnc.Application.Shared.Dtos;
using Adnc.WebApi.Shared;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WYT.Pay.Application.Contracts.Dtos.Mobao;
using WYT.Pay.Application.Contracts.Services;

namespace WYT.Pay.WebApi.Controllers
{
    /// <summary>
    /// 银行卡
    /// </summary>
    [Route("pay/[Controller]")]
    [ApiController]
    public class BrankController : AdncControllerBase
    {
        private readonly IMoBaoAppService _mobaoAppService;

        private readonly IUserContext _userContext;

        public BrankController(IMoBaoAppService mobaoAppService
            , IUserContext userContext)
        {
            _mobaoAppService = mobaoAppService;
            _userContext = userContext;
        }


        /// <summary>
        /// 银行卡绑定
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("bind")]
        public async Task<WYTActionResult<bool>> BindBankCard(BindCardDto input)
        {
            return Success(await _mobaoAppService.BindBankCard(_userContext.Id, input));
        }
        /// <summary>
        /// 银行卡解绑
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("Unbind")]
        public async Task<WYTActionResult> UnbindBankCard(SimpleDto<long> input)
        {
            return Success(await _mobaoAppService.UnbindBankCard(_userContext.Id, input.Value));
        }

        /// <summary>
        /// 获取用户银行卡列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("list")]
        public async Task<WYTActionResult<List<BankCardDto>>> GetBankCarList()
        {
            return Success(await _mobaoAppService.GetBankCarList(_userContext.Id));
        }
        /// <summary>
        /// 用户设置默认银行卡
        /// </summary>
        /// <param name="Id">银行卡记录ID</param>
        /// <returns></returns>
        [HttpPost("setDefault")]
        public async Task<WYTActionResult<Boolean>> DefaultBankCardAsync(long Id)
        {
            return Success(await _mobaoAppService.DefaultBankCardAsync(_userContext.Id, Id));
        }

        /// <summary>
        /// 获取用户默认银行卡
        /// </summary>
        /// <returns></returns>
        [HttpGet("default")]
        public async Task<WYTActionResult<BankCardDto>> GetDefaultBankCard()
        {
            return Success(await _mobaoAppService.GetDefaultBankCard(_userContext.Id));
        }
        /// <summary>
        /// 根据ID获取银行卡信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("_bankInfor")]
        [AllowAnonymous]
        public async Task<ActionResult<BankCardDto>> GetBankCardById([FromQuery] SimpleInputDto<long> input)
        {
            return Result(await _mobaoAppService.GetBankCardinfor(input.Value));
        }
    }
}
